// 返回一个 promise 异步函数
function doubleAfter2seconds(num) {
  return new Promise((resolve, reject) => {
    if (num < 3) {
      setTimeout(() => {
        resolve(2 * num)
      }, 2000);
    } else {
      reject('发生错误')
    }
  } )
}

// 走 resolve
doubleAfter2seconds(1).then(value => {
  console.log(value)
}).catch(err => {
  console.log(err)
})

// 走 reject
doubleAfter2seconds(4).then(value => {
  console.log(value)
}).catch(err => {
  console.log(err)
})